package com.study.controller;

import com.alibaba.fastjson.JSON;
import com.study.domain.Product;
import com.study.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author MI
 * @version 1.0
 * @date 2020/10/18 17:21
 */
@Slf4j
@RestController
public class ProductController {

    @Autowired
    private ProductService productService;

    //商品信息查询
    @RequestMapping("/product/{pid}")
    public Product product(@PathVariable("pid") Integer pid) {

        log.info("商品信息查询{}", pid);
        Product p = productService.findByPid(pid);
        log.info("查询到的商品信息{}", JSON.toJSONString(p));
        return p;
    }
}
